package com.huika.dealontop.control.pay.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.huika.dealontop.R;
import com.huika.dealontop.control.base.BaseAda;
import com.huika.dealontop.support.domain.CouponCodeBean;

/**
 * Description:
 * Created by zhouweiyong on 2015/11/20.
 */
public class PaySuccessLvAdapter extends BaseAda<CouponCodeBean> {
    public PaySuccessLvAdapter(Context context) {
        super(context);
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        TextView tv =null;
        if (view==null){
            view = mInflater.inflate(R.layout.item_lv_pay_success,viewGroup,false);
            tv = (TextView) view.findViewById(R.id.tv_ilps);
            view.setTag(tv);
        }else {
            tv = (TextView) view.getTag();
        }
        tv.setText(couponFormat(getItem(i).getCouponCode()));
        return view;
    }

    private String couponFormat(String coupon){
        if(coupon.length()==12){
            return String.format("%s %s %s",coupon.substring(0,4),coupon.substring(4,8),coupon.substring(8));
        }else{
            return String.format("%s %s %s",coupon.substring(0,5),coupon.substring(5,9),coupon.substring(9));
        }
    }
}
